/**
 *
 *@Author:yangwenbo
 *@Date:2021/6/1 19:20
 ***/
const mysql = require('mysql')
const { MYSQL_CONFIG } = require('../config/config')
const db = mysql.createPool(MYSQL_CONFIG)
const connectHandle = () =>{
    return new Promise((resolve, reject) => {
        db.getConnection( (err, connection) => {
            if ( err ) {
                console.error(`链接错误 ${err.stack} \n 链接ID ${connection.threadId}`);
                reject(err)
                return
            }
            resolve(connection)
        })
        // db.query(sql,(err, data)=> {
        //     if ( err ) {
        //         reject(err)
        //         return
        //     }
        //     if ( data ){
        //         resolve(data)
        //     }
        // })
    })
}
module.exports = connectHandle